layui.use(['form', 'layer', 'upload', 'laydate', 'okAddlink'], function () {
    var form = layui.form;
    var upload = layui.upload;
    var $ = layui.jquery;
    var laydate = layui.laydate;
    var $form = $('form');
    
    var sessionStorage = window.sessionStorage;
    var userId = sessionStorage.getItem("userId");
    var userName = sessionStorage.getItem("userName");

    getdata('/user/get',{id: userId},'GET',function(res){
        var data = res.data;
        form.val("userInfo", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
        "id": data.id
        ,"loginUserName": data.name
        ,"loginUserId": data.id
        ,"loginName": data.loginName
        ,"name": data.name
        ,"email": data.email
        ,"phone": data.phone
        ,"lastLoginTime": data.lastLoginTime
        ,"positionName": data.positionName
        ,"departmentName": data.departmentName
        ,"companyName": data.companyName
        ,"visitsNum": data.visitsNum
        });
        $("input[name=isAdmin][value=1]").attr("checked", data.isADMIN == 1 ? true : false);
        $("input[name=isAdmin][value=0]").attr("checked", data.isADMIN == 0 ? true : false);
        form.render();
    })

    form.on('submit(changeUser)', function(data){
        // console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
        // console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
        console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
        getdata('/user/setBaseInfo',data.field,'POST',function(res){
            if(res.success){
                layer.alert("修改成功");
            }else{
                layer.alert(res.msg);
            }
        })
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
});























